package org.naxx.security.algorithm;

public enum PolicyCombinigAlgorithm {

	DENY_OVERRIDES(
			"urn:oasis:names:tc:xacml:1.0:policy-combining-algorithm:deny-overrides"),

	ORDERED_DENY_OVERRIDES(
			"urn:oasis:names:tc:xacml:1.1:policy-combining-algorithm:ordered-deny-overrides"),

	PERMIT_OVERRIDES(
			"urn:oasis:names:tc:xacml:1.0:policy-combining-algorithm:permit-overrides"),

	ORDERED_PERMIT_OVERRIDES(
			"urn:oasis:names:tc:xacml:1.1:policy-combining-algorithm:ordered-permit-overrides"),

	FIRST_APPLICABLE(
			"urn:oasis:names:tc:xacml:1.0:policy-combining-algorithm:first-applicable"),

	ONLY_ONE_APPLICABLE(
			"urn:oasis:names:tc:xacml:1.0:policy-combining-algorithm:only-one-applicable"), ;

	private String uri;

	PolicyCombinigAlgorithm(String uri) {
		this.uri = uri;
	}

	public String getUri() {
		return this.uri;
	}

	public static PolicyCombinigAlgorithm resolve(String uri) {
		if (DENY_OVERRIDES.getUri().equals(uri)) {
			return DENY_OVERRIDES;
		} else if (ORDERED_DENY_OVERRIDES.getUri().equals(uri)) {
			return ORDERED_DENY_OVERRIDES;
		} else if (PERMIT_OVERRIDES.getUri().equals(uri)) {
			return PERMIT_OVERRIDES;
		} else if (ORDERED_PERMIT_OVERRIDES.getUri().equals(uri)) {
			return ORDERED_PERMIT_OVERRIDES;
		} else if (FIRST_APPLICABLE.getUri().equals(uri)) {
			return FIRST_APPLICABLE;
		} else if (ONLY_ONE_APPLICABLE.getUri().equals(uri)) {
			return ONLY_ONE_APPLICABLE;
		} else {
			throw new IllegalArgumentException("Unable to resolve uri '" + uri
					+ "' to policy combining algorithm.");
		}
	}
}
